package com.tools.mytools;

import android.content.Intent;
import android.util.Log;

import com.tools.mytools.encrypt.Encryption;
import com.tools.mytools.encrypt.MyKey;
import com.tools.mytools.fieldcheck.LoginCheckActivity;
import com.tools.mytools.nettest.NetworkTestActivity;
import com.tools.mytools.serialization.SerActivity;

import butterknife.OnClick;

public class MainActivity extends BaseActivity {

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_main;
    }

    @OnClick(R.id.btn_network)
    public void onClickNetwork() {
        startActivity(new Intent(this, NetworkTestActivity.class));
    }

    @OnClick(R.id.btn_getkey)
    public void onClickGetKey() {
        try {
            byte[] b = Encryption.getRawKey(MyKey.getKey().getBytes());
            Log.d("test", bytesToHex(b));
            for(int i = 0; i < b.length; i++) {
                Log.d("test", Integer.toHexString(b[i]));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @OnClick(R.id.btn_ser_test)
    public void doSerTest() {
        startActivity(new Intent(this, SerActivity.class));
    }

    private final static char[] hexArray = "0123456789ABCDEF".toCharArray();
    public static String bytesToHex(byte[] bytes) {
        char[] hexChars = new char[bytes.length * 2];
        for ( int j = 0; j < bytes.length; j++ ) {
            int v = bytes[j] & 0xFF;
            hexChars[j * 2] = hexArray[v >>> 4];
            hexChars[j * 2 + 1] = hexArray[v & 0x0F];
        }
        return new String(hexChars);
    }

    @OnClick(R.id.btn_aop_test)
    public void doAopTest() {
        startActivity(new Intent(this, LoginCheckActivity.class));
    }
}
